package com.cxp.serverdemo.bean.sys.bean;


import javax.persistence.*;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

@Entity
@Table(name = "menu")
public class Menu implements Serializable {


    private Long id;

    private String name;

    private String path;

    private String url;

    private String component;

    private Long parent;

    private String remark;

    private List<Menu> children;
    //@Formula("select r.* from role r,menu_role mr where r.id = mr.rid and mr.mid = id")
    private List<Role> roles = new ArrayList<>();

    public Menu(){
        super();
    }

    public Menu(String name, String path, String url, String component, Long parent, String remarks) {
        this.name = name;
        this.path = path;
        this.url = url;
        this.component = component;
        this.parent = parent;
        this.remark = remark;
    }

    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    @Column(name = "name",length = 100)
    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    @Column(name = "path",length = 254)
    public String getPath() {
        return path;
    }

    public void setPath(String path) {
        this.path = path;
    }

    @Column(name = "url",length = 254)
    public String getUrl() {
        return url;
    }

    public void setUrl(String url) {
        this.url = url;
    }
    @Column(name = "component",length = 254)
    public String getComponent() {
        return component;
    }

    public void setComponent(String component) {
        this.component = component;
    }
    @Column(name = "parent",length = 10)
    public Long getParent() {
        return parent;
    }

    public void setParent(Long parent) {
        this.parent = parent;
    }
    @Column(name = "remark",length = 254)
    public String getRemark() {
        return remark;
    }

    public void setRemark(String remark) {
        this.remark = remark;
    }
    @Transient
    public List<Menu> getChildren() {
        return children;
    }

    public void setChildren(List<Menu> children) {
        this.children = children;
    }

    @Transient //如果虚拟属性有GET方法必须将@Transient放有GET方法上，否则无效
    public List<Role> getRoles() {
        return roles;
    }

    public void setRoles(List<Role> roles) {
        this.roles = roles;
    }

    @Override
    public String toString() {
        return "Menu{" +
                "id=" + id +
                ", name='" + name + '\'' +
                ", path='" + path + '\'' +
                ", url='" + url + '\'' +
                ", component='" + component + '\'' +
                ", parent=" + parent +
                ", remark='" + remark + '\'' +
                '}';
    }
}
